package cn.tedu.lucky.draw.server.service.impl;

import cn.tedu.lucky.draw.server.protocol.po.ActivityRule;
import cn.tedu.lucky.draw.server.protocol.po.Rule;
import cn.tedu.lucky.draw.server.repository.ActivityRuleRepository;
import cn.tedu.lucky.draw.server.repository.RuleRepository;
import cn.tedu.lucky.draw.server.service.IActivityRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ActivityRuleService implements IActivityRuleService {

    @Autowired
    private ActivityRuleRepository activityRuleRepository;

    @Autowired
    private RuleRepository ruleRepository;

    @Override
    public List<Rule> findRuleByActivityId(Long id) {
        List<ActivityRule> activityRules = activityRuleRepository.findAllByActivityId(id);
        List<Long> ids = activityRules.stream().map(ActivityRule::getRuleId).collect(Collectors.toList());
        List<Rule> ruleList = ruleRepository.findAllById(ids);
        return ruleList;
    }
}
